package com.example.dbg.common.config;

import com.example.dbg.common.interceptor.AuthorizationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @user DBG_ZXX
 * @date 2018/10/29 8:58
 * @desc
 **/
@Configuration
public class DBGInterceptorConfig  implements WebMvcConfigurer {

    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;

//    以下WebMvcConfigurerAdapter 比较常用的重写接口
//    /** 解决跨域问题 **/
//    public void addCorsMappings(CorsRegistry registry) ;
//    /** 添加拦截器 **/
//    void addInterceptors(InterceptorRegistry registry);
//    /** 这里配置视图解析器 **/
//    void configureViewResolvers(ViewResolverRegistry registry);
//    /** 配置内容裁决的一些选项 **/
//    void configureContentNegotiation(ContentNegotiationConfigurer configurer);
//    /** 视图跳转控制器 **/
//    void addViewControllers(ViewControllerRegistry registry);
//    /** 静态资源处理 **/
//    void addResourceHandlers(ResourceHandlerRegistry registry);
//    /** 默认静态资源处理器 **/
//    void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer);


    /**
     * @desc: 配置静态资源,避免静态资源请求被拦截
     * @param registry
     * @retrun:  void
     * @Date:    2018/10/29 9:26
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

//        registry.addResourceHandler("/templates/H-ui.admin/**")
//                .addResourceLocations("classpath:/templates/H-ui.admin/");
//        registry.addResourceHandler("/templates/**")
//                .addResourceLocations("classpath:/templates/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("配置文件过滤器");

        registry.addInterceptor(authorizationInterceptor)
            //addPathPatterns 用于添加拦截规则
            .addPathPatterns("/**")
//            .addPathPatterns("/pwd/**")
            .excludePathPatterns("/login","loginI","/error","/static/**","/lib/**");
            //excludePathPatterns 用于排除拦截
            //注意content-path：ding是不用填写的
            //项目启动测试接口
//            .excludePathPatterns("/");
        }
}
